import React from 'react';
import { KfBizDataSelect, KfBizDataSelectProps, KfBizDataTableSelect, KfBizDataTableSelectProps } from 'kf-web-library';
import * as API from '@/services';
import classNames from 'classnames';

const HxArticleSelect = (props: Partial<KfBizDataSelectProps<API.Article, API.ArticlePageQueryParams>>) => {
  return (
    <KfBizDataSelect<API.Article, API.ArticlePageQueryParams>
      request={(p) => API.queryArticles({
        ...p ,
        pageSize: 1000,
      })}
      entityKeys={{
        primaryKey: 'id',
        labelKey: 'articleTitleCn',
      }}
      {...props}
      className={classNames("hx-journal-column-select", props?.className)}
    />
  );
};

const HxArticleTableSelect = (
  props: Partial<KfBizDataTableSelectProps<API.Article, API.ArticlePageQueryParams, "text">>,
) => {
  return (
    <KfBizDataTableSelect<API.Article, API.ArticlePageQueryParams, "text">
      entityTypeName={"栏目"}
      columns={[
        {
          title: '标题',
          dataIndex: "articleTitleCn",
          sorter: false,
          hideInSearch: true,
          ellipsis: true,
        },
      ]}
      request={(p) => API.queryArticles(p)}
      entityKeys={{
        primaryKey: 'id',
        labelKey: 'articleTitleCn',
      }}
      {...props}
      className={classNames("hx-journal-column-table-select", props?.className)}
    />
  );
};

interface CompoundedComponent {
  Select: typeof HxArticleSelect;
  TableSelect: typeof HxArticleTableSelect;
}

const picker: CompoundedComponent = {
  Select: HxArticleSelect,
  TableSelect: HxArticleTableSelect,
};

export default picker;
